#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<vector>

using namespace std;

//最大连续1的个数

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {

        int n = nums.size();
        int count = 0;
        int ret = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            while (nums[right] == 1)
            {
                right++;
            }
            count++;
            if(count == k)
            {
                ret = max(ret, right - left + 1);
                left = right;
                count = 0;
            }
        }
        return ret;
    }
};

int main()
{
    vector<int> vv = { 1,1,1,0,0,0,1,1,1,1,0 };
    int k = 2;
    int ans = Solution().longestOnes(vv, k);
    cout << ans << endl;
	return 0;
}